#region [file: EnderecoDAL.cs, author: Lucas Bittencourt]
// File:    EnderecoDAL.cs
// Author:  Lucas Bittencourt
// Created: terça-feira, 25 de outubro de 2011 09:26:29
// Purpose: Defines dao implementation class for class Endereco
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using DA_OOMModel;
using DA_OOMModelIDAL;

namespace DA_OOMNHibernateDAL
{
   /// <summary>
   /// Class that implements methods of IEnderecoDAL interface
   /// </summary>
   public class EnderecoDAL : NHibernateDALBase,  IEnderecoDAL 
   {
      #region CRUD methods
      /// <summary>
      /// Get all instances of Endereco
      /// </summary>     
      public List<Endereco> GetEnderecoList()
      {
         return ConvertToGenericList(base.LoadAll(typeof(Endereco)));
      }
      
      /// <summary>
      /// Get the instances of Endereco from index firstResult to index maxResult
      /// </summary>
      public List<Endereco> GetEnderecoList(int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.LoadAll(typeof(Endereco), firstResult, maxResult));
      }

      /// <summary>
      /// Load the instance of Endereco according its primary key instance.
      /// </summary>
      public Endereco Load(EnderecoPK enderecoPK)
      {
         IList cs = new ArrayList();
         string[] paramNames = new string[] { "EndIdEndereco" };
         object[] values = new object[] { enderecoPK.EndIdEndereco };
         for (int i = 0; i < paramNames.Length; i++)
             cs.Add(Expression.Eq(paramNames[i], values[i]));

         IList list = base.FindByCriterions(typeof(Endereco), cs);
         return (((list != null) && (list.Count > 0)) ? (Endereco)list[0] : null);
      }

      /// <summary>
      /// Query the instances of Endereco according its example instance.
      /// </summary>
      public List<Endereco> QueryByExample(Endereco endereco)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Endereco), endereco));
      }

      /// <summary>
      /// Query the instances of Endereco according its example instance from index firstResult to index maxResult
      /// </summary>
      public List<Endereco> QueryByExample(Endereco endereco, int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Endereco), endereco, firstResult, maxResult));
      }
      
      /// <summary>
      /// Insert the instances of Endereco
      /// </summary>
      public void Insert(Endereco enderecoObject)
      {
         base.Save(enderecoObject);
      }
      
      /// <summary>
      /// Update the instances of Endereco
      /// </summary>
      public void Update(Endereco enderecoObject)
      {
         base.Update(enderecoObject);
      }
      
      /// <summary>
      /// Delete the instances of Endereco
      /// </summary>
      public void Delete(Endereco enderecoObject)
      {
         base.Delete(enderecoObject);
      }
      #endregion
      
   
      /// <summary>
      /// Find the instances of Endereco according to its attribute endNmLogradouro
      /// </summary>
      public List<Endereco> FindByEndNmLogradouro(string endNmLogradouro) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndNmLogradouro", endNmLogradouro));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs));
      }
      
      /// <summary>
      /// Find the instances of Endereco according to its attribute endNmLogradouro, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Endereco> FindByEndNmLogradouro(string endNmLogradouro, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndNmLogradouro", endNmLogradouro));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Endereco according to its attribute endDsComplemento
      /// </summary>
      public List<Endereco> FindByEndDsComplemento(string endDsComplemento) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndDsComplemento", endDsComplemento));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs));
      }
      
      /// <summary>
      /// Find the instances of Endereco according to its attribute endDsComplemento, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Endereco> FindByEndDsComplemento(string endDsComplemento, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndDsComplemento", endDsComplemento));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Endereco according to its attribute endNuImovel
      /// </summary>
      public List<Endereco> FindByEndNuImovel(string endNuImovel) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndNuImovel", endNuImovel));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs));
      }
      
      /// <summary>
      /// Find the instances of Endereco according to its attribute endNuImovel, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Endereco> FindByEndNuImovel(string endNuImovel, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndNuImovel", endNuImovel));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Endereco according to its attribute endNmBairro
      /// </summary>
      public List<Endereco> FindByEndNmBairro(string endNmBairro) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndNmBairro", endNmBairro));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs));
      }
      
      /// <summary>
      /// Find the instances of Endereco according to its attribute endNmBairro, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Endereco> FindByEndNmBairro(string endNmBairro, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndNmBairro", endNmBairro));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Endereco according to its attribute endNuCep
      /// </summary>
      public List<Endereco> FindByEndNuCep(string endNuCep) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndNuCep", endNuCep));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs));
      }
      
      /// <summary>
      /// Find the instances of Endereco according to its attribute endNuCep, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Endereco> FindByEndNuCep(string endNuCep, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EndNuCep", endNuCep));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs, firstResult, maxResult));
      }
      
      /// <summary>
      /// Find <Code>Endereco</Code> instances by Cidade
      /// </summary>
      /// <param name="cidade"/>
      /// <returns>Endereco instance list</returns>
      public List<Endereco> FindByCidade(Cidade cidade)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Cidade", cidade));
         return ConvertToGenericList(base.FindByCriterions(typeof(Cidade), cs));
      }
      
      /// <summary>
      /// Find <Code>Endereco</Code> instances  instances in range firstResult, maxResult by Cidade
      /// </summary>
      /// <param name="cidade"/>
      /// <param name="firstResult">first result to return</param>
      /// <param name="maxResult">max result to return</param>
      /// <returns>Endereco instance list</returns>
      public List<Endereco> FindByCidade(Cidade cidade, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Cidade", cidade));
         return ConvertToGenericList(base.FindByCriterions(typeof(Cidade), cs, firstResult, maxResult));
      }
      
      /// <summary>
      /// Find <Code>Endereco</Code> instances by Pessoa
      /// </summary>
      /// <param name="pessoa"/>
      /// <returns>Endereco instance list</returns>
      public List<Endereco> FindByPessoa(Pessoa pessoa)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Pessoa", pessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Endereco), cs));
      }
      
      /// <summary>
      /// Find <Code>Endereco</Code> instances  instances in range firstResult, maxResult by Pessoa
      /// </summary>
      /// <param name="pessoa"/>
      /// <param name="firstResult">first result to return</param>
      /// <param name="maxResult">max result to return</param>
      /// <returns>Endereco instance list</returns>
      public List<Endereco> FindByPessoa(Pessoa pessoa, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Pessoa", pessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs, firstResult, maxResult));
      }
      
      /// <summary>
      /// Find <Code>Endereco</Code> instances by Estado
      /// </summary>
      /// <param name="estado"/>
      /// <returns>Endereco instance list</returns>
      public List<Endereco> FindByEstado(Estado estado)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Estado", estado));
         return ConvertToGenericList(base.FindByCriterions(typeof(Estado), cs));
      }
      
      /// <summary>
      /// Find <Code>Endereco</Code> instances  instances in range firstResult, maxResult by Estado
      /// </summary>
      /// <param name="estado"/>
      /// <param name="firstResult">first result to return</param>
      /// <param name="maxResult">max result to return</param>
      /// <returns>Endereco instance list</returns>
      public List<Endereco> FindByEstado(Estado estado, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Estado", estado));
         return ConvertToGenericList(base.FindByCriterions(typeof(Estado), cs, firstResult, maxResult));
      }

      /// <summary>
      /// Convert the IList to the generic List instance.
      /// </summary>
      private List<Endereco> ConvertToGenericList(IList enderecos)
      {
         List<Endereco> enderecoList = new List<Endereco>();
         foreach (Endereco endereco in enderecos)
         {
             enderecoList.Add(endereco);
         }
         return enderecoList;
      }      
   }
}